# -*- mode: python; -*-

Import(
    [
        "env",
        "get_option",
        "has_option",
        "http_client",
        "jsEngine",
        "version_parts",
        "version_extra",
    ]
)

env = env.Clone()


def shouldBuildGRPC(myEnv):
    return myEnv.TargetOSIs("linux") and myEnv["ENABLE_GRPC_BUILD"]


if shouldBuildGRPC(env):
    env.InjectThirdParty(libraries=["grpc"])


if not has_option("noshell") and jsEngine != "none":
    shellEnv = env.Clone()
    if env.TargetOSIs("windows"):
        shellEnv.Append(LIBS=["winmm"])

        generatedMongoManifest = shellEnv.Substfile(
            "mongo.manifest.in",
            SUBST_DICT=[
                ("@mongo_version_major@", version_parts[0]),
                ("@mongo_version_minor@", version_parts[1]),
                ("@mongo_version_patch@", version_parts[2]),
                ("@mongo_version_extra@", version_parts[3]),
                ("@mongo_version_extra_str@", version_extra),
            ],
        )
        shellEnv.Alias("generated-sources", generatedMongoManifest)
        shellEnv.Depends("mongo.res", generatedMongoManifest)

    mongo_shell = shellEnv.BazelProgram(
        target="mongo",
        source=[],
        LIBDEPS=[],
        AIB_COMPONENT="jstestshell",
        AIB_COMPONENTS_EXTRA=[
            "devcore",
            "dist-test",
            "integration-tests",
            "mongo",
            "serverless-test",
        ],
    )

env.CppUnitTest(
    target="shell_test",
    source=[],
    LIBDEPS=[],
)
